#include "Tortoise.h"
#include "config.h"

Tortoise::Tortoise(b2World * w, const CCPoint & point)
: Obstacle(w)
, pos(point)
{
}

Tortoise::~Tortoise()
{
}

bool Tortoise::init()
{
  do
  {
    createBody();
    setPTMRatio(PTM_RATIO);
    initWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("tortoise.png"));
    return true;
  }
  while (0);
  return false;
}

Tortoise * Tortoise::create(b2World * w, const CCPoint & point)
{
  Tortoise * pTortoise = new Tortoise(w, point);
  if (pTortoise && pTortoise->init())
  {
    pTortoise->autorelease();
    return pTortoise;
  }
  else
  {
    CC_SAFE_DELETE(pTortoise);
    return NULL;
  }
}

void Tortoise::createBody()
{
  b2BodyDef groundBodyDef;
  groundBodyDef.position.Set(pos.x, pos.y);

  m_pB2Body = pWorld->CreateBody(&groundBodyDef);

  b2PolygonShape groundBox;

  groundBox.SetAsBox(0.5, 0.5);
  m_pB2Body->CreateFixture(&groundBox, 0);

  m_pB2Body->SetUserData((GameEntity *)this);
}
